package com.ambition.mallchat.common.websocket.service.adapter;

import com.ambition.mallchat.common.user.domain.entity.User;
import com.ambition.mallchat.common.websocket.domain.enums.WSRespTypeEnum;
import com.ambition.mallchat.common.websocket.domain.vo.resp.WSBaseResp;
import com.ambition.mallchat.common.websocket.domain.vo.resp.WSLoginSuccess;
import com.ambition.mallchat.common.websocket.domain.vo.resp.WSLoginUrl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;

/**
 * @program: mallchat-learnning
 * @ClassName WebsocketAdapter
 * @description:
 * @author: oldTea
 * @create: 2023-10-28 00:59
 * @Version 1.0
 **/
public class WebsocketAdapter {

    public static WSBaseResp<?> buildResp(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WSBaseResp<WSLoginUrl> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        wsBaseResp.setData(new WSLoginUrl(wxMpQrCodeTicket.getUrl()));
        return wsBaseResp;
    }

    public static WSBaseResp<?> buildResp(User user, String token) {
        WSBaseResp<WSLoginSuccess> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SUCCESS.getType());
        WSLoginSuccess build = WSLoginSuccess.builder()
                .avatar(user.getAvatar())
                .name(user.getName())
                .token(token)
                .uid(user.getId())
                .build();
        resp.setData(build);
        return resp;

    }

    public static WSBaseResp<?> buildWaitAuthorize() {
        WSBaseResp wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_SCAN_SUCCESS.getType());
        return wsBaseResp;
    }
}